package com.obje.design_model.one;

public class SimpleFactory {
    public static void main(String[] args) {
        Operation operation = OperationFactory.operaCreat("/");
        operation.numberA = 1;
        operation.numberB = 12;
        System.out.println(operation.result());
    }
}
class OperationFactory{
    public static Operation operaCreat(String operat) {
        Operation operation = null;
        switch (operat) {
            case "+":
                operation = new OperationAdd();
                break;
            case "-":
                operation = new OperationSub();
                break;
            case "*":
                operation = new OperationMul();
                break;
            case "/":
                operation = new OperationDiv();
                break;
        }
        return operation;
    }
}
abstract class Operation{
    double numberA;
    double numberB;

    double getNumberA() {
        return numberA;
    }

    void setNumberA(double numberA) {
        this.numberA = numberA;
    }

    double getNumberB() {
        return numberB;
    }

    void setNumberB(double numberB) {
        this.numberB = numberB;
    }
    double result(){
        double result = 0;
        return result;
    }
}

class OperationAdd extends Operation{
    @Override
    public double result(){
        double result = 0;
        result = numberA + numberB;
        return result;
    }
}
class OperationSub extends Operation{
    @Override
    public double result(){
        double result = 0;
        result = numberA - numberB;
        return result;
    }
}
class OperationMul extends Operation{
    @Override
    public double result(){
        double result = 0;
        result = numberA * numberB;
        return result;
    }
}
class OperationDiv extends Operation{
    @Override
    public double result(){
        double result = 0;
        try {
            result = numberA / numberB;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}